<?php
    require('config/config.php');
    include('header.php');
		
	$id = $_GET['serviceId'];
	$service = Service::recherche(intval($id));
	$machines = Machine::recherche(array("service"=>$service));

?>	
    <!-- Header -->
    <header class="container_12 " id="header">
        <div class="grid_3 alpha">
            <img src="./stylesheets/images/logo1.png" alt="Logo"/>
        </div>
	
<?php
    require 'tableauCriticite.php';
?>
    </header>
    <!-- End Header -->
    <!-- Content -->
    <div id="statutService"></div>
    <div class="clear"></div>
    <section class=" content">
<?php
    require 'menu.php';
?>
 <div>
         <table class="tabInfos">
            <caption>Machines du service <?php echo $service->getNomService();?></caption>
            <thead>
                    <tr>
                      <th>Machine</th>
                      <th>Service</th>
                      <th>Status</th>
                      <th>Dernier check</th>
                      <th>Durée</th>
                      <th>Informations</th>
                    </tr>
                </thead>
            <tbody>
<?php			
				$now = new DateTime();
				$dayNow = (int)$now->format('j');
				$checkNom = "";
				foreach($machines as $machine) {
					
					$informations = Evenement::getInformationByMachine($machine);
					foreach($informations as $info) {
					
						$stringToDate = DateTime::createFromFormat('Y-m-j H:i:s',  $info['checkD']);
						$interval = $stringToDate->diff($now);
						$dayRow = (int)$stringToDate->format('j');
						$lastModif = $interval->d."j ". $interval->h ."h ". $interval->i ."m ". $interval->s ."s";
						
						echo '<tr>';
						if($checkNom != $info['machine']){
							echo '<td>'.$info['machine'].'</td>';
							$checkNom = $info['machine'];
						}else{
							echo '<td></td>';
						}
						 echo '<td>'.$info['service'].'</td>';
						 echo '<td>'.$info['status'].'</td>';
						 echo '<td>'.$info['checkD'].'</td>';
						 echo '<td>'. $lastModif .'</td>';
						 echo '<td><p>' .$info['infos']. '</p></td>';
						 echo '</tr>';
					 }
				}
?>		
            </tbody>
        </table>
    </div>
    </section>
    <!-- End Content-->
 <?php
    include 'footer.php';
 ?>
</body>
</html>
